<?php

/*
 * This file is part of the slince/dragbox package.
 *
 * (c) Slince <taosikai@yeah.net>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace DragBox\Common\Filesystem\Index;

use DragBox\Common\Filesystem\FileInterface;

class SqlLiteIndexer implements IndexerInterface
{
    /**
     * @var \PDO
     */
    protected $pdo;

    protected $file;

    public function __construct($sqlFile)
    {
        $this->pdo = new \PDO('sqlite:' . $sqlFile);
    }

    public function initialize()
    {
        if (!file_exists($this->file)) {
            $ddl = @file_get_contents(__DIR__ . '/schema.sql');
            $this->pdo->exec($ddl);
        }
    }


    /**
     * {@inheritdoc}
     */
    public function index(FileInterface $file)
    {
        $sql = 'insert or update';
    }

    public function find($key)
    {
        $sql = "SELECT * FROM file_indexs WHERE file_key = '{$key}' limit 1";
        $stmt = $this->pdo->query($sql);
        $data = $stmt->fetch(\PDO::FETCH_ASSOC);
        $file = 
    }
}